package com.lc.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lc.websocket.MySorketHandler;

@Controller
@RequestMapping("/im")
public class IMController {

	@Bean
	public MySorketHandler mySorketHandle() {
		return new MySorketHandler();
	}

	@RequestMapping("/page")
	public String page(HttpServletRequest request, HttpServletResponse response) {
		return "IMpage";
	}

	@ResponseBody
	@RequestMapping("/push")
	public String push(@RequestParam(required = false) String sessionId, 
			HttpServletResponse response) {
		String msg = "";
		if (StringUtils.isEmpty(sessionId)) {
			msg = mySorketHandle().pushMsg("服务器推送信息了");
			System.out.println(msg);
		} else {
			msg = mySorketHandle().pushMsg(sessionId, "服务器推送信息了");
			System.out.println(msg);
		}
		return msg;
	}
}